package com.panshi.controller;

import com.panshi.service.ArticlrService;
import com.panshi.util.CommonResult;
import com.panshi.util.TimeVO;
import com.panshi.vo.ArticlrVO;
import com.panshi.vo.PageSizeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
@CrossOrigin
public class ArticlrController {

    @Autowired
    private ArticlrService articlrService;

    @PostMapping("/artQu")
    public List<List<ArticlrVO>> findArtQuery(@RequestBody PageSizeVO pageSizeVO){
        log.info("查询文章");
        List<ArticlrVO> artQuery = articlrService.findArtQuery(pageSizeVO);
        List<ArticlrVO> arttQuery = articlrService.findArttQuery(pageSizeVO);

        arttQuery.forEach((e)->{
            e.setTime(TimeVO.getTimeFormatText(e.getCreateTime()));
        });

        List<List<ArticlrVO>> list = new ArrayList<>();
        list.add(artQuery);
        list.add(arttQuery);
        return list;
    }

    @GetMapping("/artDe/{aid}")
    public CommonResult<String> deleteArt(int aid) {

        articlrService.deleteArt(aid);
        return new CommonResult<String>();
    }



    @GetMapping("/artDeNo/{aid}")
    public CommonResult<String> deleteArtNo(int aid) {
        articlrService.deleteArtNo(aid);
        return new CommonResult<String>();
    }

}
